<form id="submit-form" action="" method="post">    
    <div style="padding:10px;" id="sending">
		<ul>
			<li style="font-weight:bold;">{phrase var='contactimporter.sending'} (<span id="success">1</span>/<span id="total">{$iTotal}</span>) <img style="float:right;" src="{$sCorePath}module/contactimporter/static/image/add.gif"/></li>
			<li>
				<div id="progressbar">
					<div id="percent"></div>
				</div>
			</li>
		</ul>
	</div>
	<div style="float:right;">
		<input type="button" class="button" value="{phrase var='contactimporter.close'}" id="close-button" />
	</div>
	<div class="clear"></div>
</form>
{literal}<script language="javascript" type="text/javascript">
var url = "{/literal}{$sMainUrl}{literal}";
var total = "{/literal}{$iTotal}{literal}";
var provider = "{/literal}{$sProvider}{literal}";
var message = $('#message').val();    
var bIsDebug = "{/literal}{$bIsDebug}{literal}";
$Behavior.initJs = function() {	    
    var popup = $('#submit-form').closest(".js_box");
    var btDiv = popup.find(".js_box_close");	
    var message = $('#message').val();
    var contacts = getItemsChecked('items[]',',');
    $('#close-button').click(function(evt) {   
        tb_remove();
        location.href = url;
        return false;
    });
    setTimeout(function(){btDiv.hide();}, 1);    
    setTimeout(function(){sendInvite(contacts);}, 30);        
}
sendInvite = function(contacts) {    
    $Core.ajax('contactimporter.sendInvite',
    {
        params:
        {            
            provider: provider,                
            message: message,                
            total: total,                
            contacts: contacts
        },
        type: 'POST',
        success: function(response)
        {            
            var isJson = 0;
            response = jQuery.trim(response);            
            if (response.substring(0, 1) == '{')
            {
               isJson = 1; 
            }                                  
            if (isJson) {
                var response = $.parseJSON(response);
                var percent = response['percent'];
                var success = response['success'];
                var contacts = response['contacts'];
                var error = response['error'];
                $("#success").html(success);
                $("#percent").css('width', percent);
                if (success < total) {
                    sendInvite(contacts);
                } else {
                    setTimeout(function(){location.href = url;}, 300);    
                } 
            }
            else            
            {
                $('#sending').html(response);                
            }
        }
    });
}
</script>{/literal}